﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.Controllers;
using QLBH.Models;

namespace QLBH.Modules
{
    public partial class ucBranchs : UserControl
    {
        private BranchsController objController;
        public ucBranchs()
        {
            InitializeComponent();
            objController = new BranchsController(this);
        }
        public void DisplayData(List<QLBH.Models.BranchsModel> model)
        {
            this.dataGridView.DataSource = model;
        }

        private void ucBranchs_Load(object sender, EventArgs e)
        {
            this.dataGridView.AutoGenerateColumns = false;
            objController.loadData();
            if (dataGridView.SelectedRows.Count <= 0)
            {
                btnDelete.Enabled = false;
                btnEdit.Enabled = false;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            objController.Add();
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            objController.Edit();
        }

        public BranchsModel SelectItem()
        {
            if (dataGridView.SelectedRows.Count > 0)
            {
                return dataGridView.SelectedRows[0].DataBoundItem as BranchsModel;
            }
            else
            {
                return null;
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            objController.Delete();
        }
    }
}
